<?php

class Mask {

	public static $CEP = 0;
	public static $CNPJ = 1;
	public static $CPF = 2;
	public static $TELEFONE = 3;

	public static function maskNumber($str,$type) {
		if( strlen($str) == 8 && $type == self::$CEP )
			return substr($str, 0, 2).".".substr($str, 2, 3)."-".substr($str, 5);
		if( strlen($str) == 14 && $type == self::$CNPJ )
			return substr($str, 0, 2).".".substr($str, 2, 3).".".substr($str, 5, 3)."/".substr($str, 8, 4)."-".substr($str, 12, 2);
		if( strlen($str) == 11 && $type == self::$CPF )
			return substr($str, 0, 3).".".substr($str, 3, 3).".".substr($str, 6, 3)."-".substr($str, 9, 2);
		if( strlen($str) == 10 && $type == self::$TELEFONE )
			return "(".substr($str, 0, 2).")".substr($str, 2, 4)."-".substr($str, 6, 4);
		return "";
	}
	
	public static function unMaskNumber($str) {
		return str_replace( array("(",")","/","-","."), "", $str );
	}
	
}

?>